#ifndef USER_DEBUG_DEBUG_H_
#define USER_DEBUG_DEBUG_H_

#include <stdint.h>
#include <stdbool.h>
#include <ti/display/Display.h>
#include <xdc/runtime/System.h>
#include <ti/drivers/UART.h>

extern Display_Handle dispHandle;

void Driver_uart0_init(uint32_t bpsUart0);
void Driver_uart0_open();


extern void DebugPrintf_init(UART_Handle handle);
extern void myUserFlush(void);
/*
 * Display module will output "\n" every times
 *
 */
#if !defined(Display_DISABLE_ALL) || (!Display_DISABLE_ALL)

#define Debug(fmt, ...)                Display_printf(dispHandle, 0, 0, fmt, ##__VA_ARGS__)

#else

#define DEBUG_NEW_LINE  "\r\n"
#define Debug(fmt, ...)                  do{System_printf(fmt, ##__VA_ARGS__);myUserFlush();}while(0)
#define Debugln(fmt, ...)                do{System_printf(fmt, ##__VA_ARGS__);System_printf(DEBUG_NEW_LINE);myUserFlush();}while(0)
#define DebugHex(buf, len)               do{for(uint8_t _z = 0; _z < len; _z++)\
                                           {System_printf("%02x ", buf[_z]);} \
                                            System_printf(DEBUG_NEW_LINE);\
                                            myUserFlush();}\
                                            while(0)


#  undef Display_init
#  undef Display_open
#  undef Display_Params_init
#  undef Display_clear
#  undef Display_clearLines
#  undef Display_printf
#  undef Display_print0
#  undef Display_print1
#  undef Display_print2
#  undef Display_print3
#  undef Display_print4
#  undef Display_print5
#  undef Display_vprintf
#  undef Display_getType
#  undef Display_control
#  undef Display_close

#  define Display_init()
#  define Display_open(id, params)    NULL
#  define Display_Params_init(params)
#  define Display_clear(handle)
#  define Display_clearLines(handle, fromLine, toLine)
#  define Display_printf(handle, line, col, fmt, ...)                   Debugln(fmt, ##__VA_ARGS__);
#  define Display_print0(handle, line, col, fmt)                        Debugln(fmt)
#  define Display_print1(handle, line, col, fmt, a0)                    Debugln(fmt, a0)
#  define Display_print2(handle, line, col, fmt, a0, a1)                Debugln(fmt, a0, a1)
#  define Display_print3(handle, line, col, fmt, a0, a1, a2)            Debugln(fmt, a0, a1, a2)
#  define Display_print4(handle, line, col, fmt, a0, a1, a2, a3)        Debugln(fmt, a0, a1, a2, a3)
#  define Display_print5(handle, line, col, fmt, a0, a1, a2, a3, a4)    Debugln(fmt, a0, a1, a2, a3, a4)
#  define Display_vprintf(handle, line, col, fmt, va)                   Debugln(fmt, va)
#  define Display_getType(handle) Display_Type_INVALID
#  define Display_control(handle, cmd, arg) (DISPLAY_STATUS_UNDEFINEDCMD)
#  define Display_close(handle)
#endif


#endif /* USER_DEBUG_DEBUG_H_ */

